package com.dotflat.check.service;

import com.dotflat.check.domain.Checker;
import com.dotflat.util.excelUtil.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class TianBoMqttService {

    @Autowired
    private MqttClient tianboMqttClient;

    public void sendMessage(String topic, String payload) throws MqttException {
        // 发布消息
        MqttMessage mqttMessage = new MqttMessage();
        mqttMessage.setPayload(payload.getBytes()); // 设置消息内容
        tianboMqttClient.publish(topic, mqttMessage); // 发布消息到主题

        log.info("try to publish message :" + payload);
        log.info("Message published to topic: " + topic);
    }

}

